/*
 * Copyright (c) 2024, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
 */

import { CancelResponse, ContinueResponse } from '@salesforce/salesforcedx-utils-vscode';
import { LWC } from './componentUtils';

export type DirFileNameSelection = {
  fileName: string;
  outputdir: string;
  template?: 'ApexUnitTest' | 'BasicUnitTest';
  extension?: 'JavaScript' | 'TypeScript';
};

export type LocalComponent = DirFileNameSelection & {
  type: string;
  suffix?: string;
};


export type OneOrMany = LocalComponent | LocalComponent[];
export type ContinueOrCancel = ContinueResponse<OneOrMany> | CancelResponse;
export type ComponentName = {
  name?: string;
};

export type DeployRetrieveOperationType = 'deploy' | 'retrieve' | 'push' | 'pull' | 'delete';
export const isContinue = (continueOrCancel: ContinueOrCancel): continueOrCancel is ContinueResponse<OneOrMany> =>
  Reflect.get(continueOrCancel, 'type') === 'CONTINUE';

export const isComponentName = (component: ComponentName | LocalComponent): component is ComponentName =>
  Reflect.has(component, 'name');

export const isDirFileNameSelection = (
  component: DirFileNameSelection | LocalComponent
): component is DirFileNameSelection => Reflect.has(component, 'fileName') && Reflect.has(component, 'outputdir');

export const isLwcComponentPath = (componentDir: string): boolean => componentDir.endsWith(LWC);
